<!DOCTYPE html>
<html class="x-admin-sm">
    <head>
        @include('common.meta')
        @include('common.script')
    </head>
    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form">
                    <div class="layui-form-item">
                        <label for="L_username" class="layui-form-label">
                            <span class="x-red">*</span>角色昵称</label>
                        <div class="layui-input-inline">
                            <input type="hidden" name="_token" value="{{ csrf_token() }}" />
                            <input type="hidden" name="role_id" value="{{ $role->id }}" />
                            <input type="text" id="L_username" name="role_name" required="" value="{{ $role->role_name }}" lay-verify="role_name" autocomplete="off" class="layui-input"></div>
                    </div>

                    <div class="layui-form-item">
                        <label for="L_username" class="layui-form-label">
                            <span class="x-red">*</span>权限</label>
                        <div class="layui-input-block">
                            @foreach($perms as $v)
                                @if(in_array($v->id,$own_pers))
                                    <input type="checkbox" checked name="permission_id[]" value="{{ $v->id }}" title="{{ $v->per_name }}" lay-skin="primary" />
                                @else
                                    <input type="checkbox" name="permission_id[]" value="{{ $v->id }}" title="{{ $v->per_name }}" lay-skin="primary" />
                                @endif
                            @endforeach
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label for="L_repass" class="layui-form-label"></label>
                        <button class="layui-btn" lay-filter="auth" lay-submit="">授权</button></div>
                </form>
            </div>
        </div>
        <script>layui.use(['form', 'layer','jquery'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                layer = layui.layer;

                //自定义验证规则
                form.verify({
                    role_name: function(value) {
                        if (value.length < 2) {
                            return '角色名至少得2个字符啊';
                        }
                    },
                });

                //监听提交
                form.on('submit(auth)', function(data) {
                    //发异步，把数据提交给php
                    $.ajax({
                        url:'/admin/role/doauth',
                        type:'POST',
                        dataType:'json',
                        data:data.field,
                        success:function (res){
                            // 判断
                            if(res.code == 1){
                                layer.msg(res.message,{icon:1},function (){
                                    parent.location.reload(true)
                                })
                            }else {
                                layer.msg(res.message,{icon:5})
                            }
                        },
                        error:function (res){
                        }
                    });
                    return false;
                });

            });</script>
        <script>var _hmt = _hmt || []; (function() {
                var hm = document.createElement("script");
                hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
            })();</script>
    </body>

</html>